import React, { useEffect, useState } from 'react';
import { getChannel } from 'api/article';
import { Select } from 'antd';
const { Option } = Select;

// 声明状态
// 把相关代码复制过去

export default function Channel(props) {
  const [channel, setChannel] = useState([]);
  //封装获取频道接口
  const loadChannel = async () => {
    const res = await getChannel();
    // console.log(res.data.channels);
    setChannel(res.data.channels);
  };
  // 发请求
  useEffect(() => {
    loadChannel();
  }, []);
  return (
    <Select {...props} style={{ width: 200 }}>
      {channel.map((item) => {
        return (
          <Option value={item.id} key={item.id}>
            {item.name}
          </Option>
        );
      })}
    </Select>
  );
}
